#include "config.hh"
#include "toml.hh"
#include <iostream>
#include <stdexcept>
#include <string>

namespace ngintoy
{
    namespace config
    {
        config::config(std::string const& path)
        {
            auto c = toml::parse_file(path);

            // version validation
            auto version = c->get_qualified_as<int64_t>("ngintoy.version");
            if (!version) throw std::runtime_error{"not a valid ngintoy configuration file: " + path};
            if (*version != 1) throw std::runtime_error{"ngintoy configuration version unsupported, support only version 1: " + path};

            // DEBUG
            std::cerr << *c << "\n";

            renderer = c->get_qualified_as<std::string>("context.renderer").value_or("");
            platform = c->get_qualified_as<std::string>("context.platform").value_or("");
        }
    }
}

